package com.zaprit.search.web;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Root
 */
@Controller
public class PageRedirectionController
{
	/**
	 * @param page
	 * @param model
	 * @param session
	 * @return Redirected view
	 */
	@RequestMapping(value = "site/{page}")
	public String getPage(@PathVariable("page") String page, Model model, HttpSession session)
	{
		// AuthorizationManager authorizationManager = (AuthorizationManager)
		// Context.getBean("appUserAuthService");
		// AppUserService appUserService = (AppUserService)
		// Context.getBean("appUserService");
		String redirectPage = "website/home";
		/*
		 * try { boolean loggedIn = authorizationManager.isLoggedIn(); if
		 * (loggedIn) { User user = authorizationManager.getLoggedUser();
		 * session.setAttribute("user",
		 * appUserService.getUserByUserName(user.getUsername())); switch (page)
		 * { case "login": case "signUp": redirectPage =
		 * "forward:/web/portal/dashboard"; break; case "home": redirectPage =
		 * "website/home"; break; case "howItWorks": redirectPage =
		 * "website/how_it_works"; break; case "termsConditions": redirectPage =
		 * "website/terms_conditions"; break; case "career": redirectPage =
		 * "careers"; break; case "contact": redirectPage = "website/contact";
		 * break; case "help": redirectPage = "help"; break; case "error":
		 * redirectPage = "noPermission"; break; case "404": redirectPage =
		 * "404"; break; case "features": redirectPage = "website/features";
		 * break; case "pricing": redirectPage = "website/pricing"; break;
		 * default: redirectPage = "login"; break; } } else { switch (page) {
		 * case "login": redirectPage = "login"; break; case "signUp":
		 * redirectPage = "signUp"; break; } } } catch (InvalidUserException e)
		 * { e.printStackTrace(); } catch (UserException e) {
		 * e.printStackTrace(); }
		 */
		return redirectPage;
	}

	/**
	 * @param page
	 * @param model
	 * @param session
	 * @return Redirected view
	 */
	@RequestMapping(value = "portal/{page}")
	public String getPortalPage(@PathVariable("page") String page, Model model, HttpSession session)
	{
		// AuthorizationManager authorizationManager = (AuthorizationManager)
		// Context.getBean("appUserAuthService");
		// AppUserService appUserService = (AppUserService)
		// Context.getBean("appUserService");
		String redirectPage = "website/home";
		/*
		 * try { boolean loggedIn = authorizationManager.isLoggedIn(); if
		 * (loggedIn) { User user = authorizationManager.getLoggedUser();
		 * session.setAttribute("user",
		 * appUserService.getUserByUserName(user.getUsername())); switch (page)
		 * { case "signIn": case "signUp": redirectPage = "forward:dashboard";
		 * break; case "dashboard": redirectPage = "dashboard"; break; case
		 * "campaign": redirectPage = "campaign"; break; case "profile":
		 * redirectPage = "profile"; break; case "wizard": redirectPage =
		 * "form_wizard"; break; case "thinkpad": redirectPage = "thinkpad";
		 * break; case "invoice": redirectPage = "invoice"; break; case "help":
		 * redirectPage = "help"; break; case "404": redirectPage = "404";
		 * break; default: redirectPage = "noPermission"; break; } } else {
		 * switch (page) { case "login": redirectPage = "login"; break; case
		 * "signUp": redirectPage = "signUp"; break; } } } catch (UserException
		 * e) { e.printStackTrace(); } catch (InvalidUserException e) {
		 * e.printStackTrace(); }
		 */
		return redirectPage;
	}
}
